Efficient parallel bitwise sweep during garbage collection

ABSTRACT

A method, system, and program for efficient parallel bitwise sweeps of larger objects during garbage collection are provided. During a bitwise sweep, a helper thread scans a mark vector looking for a consecutive sequence of unmarked bits of a sufficient length following a marked bit. Once a consecutive sequence of unmarked bits of a sufficient length following a marked bit is detected, the helper thread fetches the size of a marked object corresponding to the marked bit. If the size of the marked object exceeds a size represented by the consecutive sequence of unmarked bits, the remainder of the bits representing the marked object are skipped, such that once a marked object is identified as potentially exceeding an object fetch threshold the helper thread efficiently skips the remainder of the bits represents the marked object and continues scanning for a number of consecutive zeroes indicating free space.

CROSS-REFERENCE TO RELATED APPLICATION

The present application is related to the following co-pendingapplications:

(1) U.S. patent application Ser. No. ______ Attorney Docket No.AUS920040102US1); and

(2) U.S. patent application Ser. No. ______ (Attorney Docket No.AUS920040444US1).

BACKGROUND OF THE INVENTION

1. Technical Field

The present invention relates in general to improved garbage collectionand in particular to improved efficiency in handling large objectsduring garbage collection. Still more particularly, the presentinvention relates to improved efficiency in handling a parallel bitwisesweep of larger objects during garbage collection.

2. Description of the Related Art

Software systems, such as the Java Virtual Machine (JVM), that employgarbage collection typically provide an explicit call for allocatingobjects, but no explicit call for freeing objects. Instead, in a systemthat employs garbage collection, when available storage on a heap isexhausted, all operations are suspended and garbage collection isinvoked to replenish the free storage.

A common garbage collection algorithm is called “mark and sweep”. Duringthe mark phase, all Java objects that are still accessible to a programare identified and marked. Next, during the sweep phase, unmarkedobjects of the heap are identified as free space. In particular, freespace is typically identified as the space bounded by marked objects orby the beginning or end of the heap.

In particular, during the sweep phase, the free spaces that are of asufficiently large size are considered free items that may be arrangedinto lists or structures that facilitate subsequent object allocation.Any free memory fragments that are not of sufficient large size aredeemed unnecessary and are not included in the list.

In sweep phrase implementation, it is common for a garbage collectionalgorithm to require that the size of objects currently within the heapbe derivable from an examination of the object. Additionally, somegarbage collection algorithms may require that free memory fragmentshave a derivable size.

One approach for facilitating object and fragment size derivation is toinclude a prefix to every object and fragment, where the prefixindicates a size field. Another approach for facilitating object andfragment size derivation is by implementing a bitwise sweep algorithm.To implement a bitwise sweep algorithm, a dedicated bit array that isindependent of the heap identifies marked objects where each bitrepresents a fixed storage size (e.g. 8 bytes) and each object isaligned to this size. At the onset of the mark phase, the dedicated bitarray is cleared. Then, referenced objects are marked by setting the bitthat represents the starting location of the object. Next, during thesweep phase, the bitwise sweep algorithm is implemented by scanning thededicated bit array, searching for runs of zero bits bound on each sideby marked bits. When a sufficiently large run of zeroes bound by markedbits is located, the object at the beginning of the run is examined andits size fetched. The size of the initial marked object is thensubtracted from the size represented by the run of zeroes and if theresulting size is sufficiently large, the storage bound by the markedobjects is considered a free item and is saved in a way to allow it tobe used for subsequent object allocation.

Garbage collection becomes more complex in a multiprocessor system. Inparticular, a parallel garbage collector may be implemented to handlegarbage collection in a multiprocessor system. A parallel garbagecollector may implement sufficient helper threads to use all theavailable processors during garbage collection. In one example of animplementation of a parallel sweep phase, the heap may be divided amongmultiple sections so that each helper thread can work on unique sectionsand not impede the other helper threads.

When all sections have been processed by helper threads, the helperthreads are suspended and the garbage collector enters single threadmode. In single thread mode, a single thread examines all the sectiondata and may identify free items that span sections. The single threadarranges all the identified free items into appropriate structures forsubsequent allocations. In particular, during single thread mode, allother threads of the Java process are suspended and only one process isused by the Java process.

When a Java application is run on a multiprocessors system, it isimportant that parallel garbage collectors are as efficient as possible.First, it is important to make helper threads function as efficiently aspossible because when the helper threads are executing on the multipleprocessors, the Java application threads are suspended. In particular,it is important to have helper threads finish sweeping all sectionsclose to the same time to reduce the amount of time that processorsremain idle waiting for other helper threads to finish. Second, it isimportant to make the single thread mode runtime as short as possiblebecause when the single thread executes during single thread mode, allother Java threads are suspended.

The bitwise sweep algorithm is one efficient method of facilitatingsweeps when objects are small, but the current bitwise sweep algorithmis inefficient when used to facilitate object size derivation for largeobjects, and in particular large objects that are significantly largerthan the size requirement for addition to a free list. For example,large database applications and applications that display images mayinstantiate objects that are several megabytes in size, while thetypical free list may only require unmarked objects to be severalhundred bytes to be eligible for storage in a free list. Under thecurrent bitwise sweep, each bit representing the length of the initialmarked object must be scanned and a marked bit reached before the sizeof the object is fetched. Thus, the current bitwise sweep algorithm isinefficient because if the size of the fetched object is large, manybits are unnecessarily scanned.

In allocating sections, multiple small sections maybe allocated topromote sweep efficiency. In particular, when there are multiple smallsections, the time that helper threads sweep each section is reduced,allowing the helper threads to complete sweeping all the sections moreclosely to each other. However, as the number of small sectionsincreases, the amount of time required for single thread mode increases,which may effectively decrease the efficiency gained from allocatingmultiple small sections. In addition, while allocating multiple smallsections may promote efficient sweeps of small objects, sweepingmultiple small sections for larger objects is inefficient. Inparticular, when a larger marked object extends across multiple smallsections, in a bitwise sweep, each bit of each portion of the largerobject is inefficiently scanned within each section.

Therefore, in view of the foregoing, there is a need for a method,system, and program for improving the efficiency of bitwise sweeps in aparallel garbage collector and the efficiency of section dispersal toimprove the efficiency of handling larger objects, and in particular forhandling objects that are substantially larger than the size requiredfor addition of the object to the free list.

SUMMARY OF THE INVENTION

Therefore, an improved method, system, and program provide improvedgarbage collecting and in particular provide improved efficiency inhandling large objects during garbage collection. Still moreparticularly, the method, system, and program of the present inventionprovides improved efficiency in handling a parallel bitwise sweep oflarger objects during garbage collection.

According to one aspect, each bit of a bit vector corresponds to a fixedsized block of a heap. During a bitwise sweep, a helper thread scans themark vector looking for a consecutive sequence of unmarked bits of asufficient length following a marked bit. Once a consecutive sequence ofunmarked bits of a sufficient length following a marked bit is detected,the helper thread fetches the size of a marked object corresponding tothe marked bit. If the size of the marked object exceeds a sizerepresented by the consecutive sequence of unmarked bits, the remainderof the bits representing the marked object are skipped, such that once amarked object is identified as potentially exceeding an object fetchthreshold the helper thread efficiently skips the remainder of the bitsrepresents the marked object and continues scanning for a number ofconsecutive zeroes indicating free space.

According to another aspect, the number of consecutive zeroes indicatingfree space that follow a marked object are counted until another markedbit is found. Once another marked bit is found, the number ofconsecutive zeroes indicating free space that follow the marked objectare compared with a free list size threshold. If the number ofconsecutive zeroes exceeds the free list threshold, then the free spaceis added to a free item list.

According to yet another aspect, portions of the memory heap and bitvector corresponding to the memory heap may be distributed amongmultiple sections. Multiple helper threads are then concurrently invokedto perform the bitwise sweep in parallel. In particular, each helperthread acquires the data structure for a particular section and performsa bitwise sweep, where the data structure for a section indicates theportion of the memory heap and the bit vector assigned to the section.Once a helper thread completes the bitwise sweep of a section, thehelper thread checks to see if any additional sections remainunprocessed, and if so, acquires the next section. Once all the helperthreads are completed, a single thread accumulates the free itemsidentified for each section and combines any free space identified atthe beginning or end of a section to determine additional free itemsthat span sections.

BRIEF DESCRIPTION OF THE DRAWINGS

The novel features believed characteristic of the invention are setforth in the appended claims. The invention itself however, as well as apreferred mode of use, further objects and advantages thereof, will bestbe understood by reference to the following detailed description of anillustrative embodiment when read in conjunction with the accompanyingdrawings, wherein:

FIG. 1 is a block diagram depicting one embodiment of the hardware andsoftware implemented in a computer system through which the presentmethod, system, and program may be implemented;

FIG. 2 is a block diagram depicting a block diagram of the memorymanagement and allocation within a JVM in accordance with the method,system, and program of the present invention;

FIG. 3 is an illustrative example depicting an efficient parallelbitwise sweep in accordance with the method, system, and program of thepresent invention;

FIG. 4 is a high level logic flowchart depicting a process and programfor performing a parallel bitwise sweep in accordance with the method,system, and program of the present invention;

FIG. 5 is a high level logic flowchart depicting a process and programfor initially distributing sections within a memory heap for efficientsweeps of larger objects in accordance with the method, system, andprogram of the present invention; and

FIG. 6 is a high level logic flowchart depicting a process and programfor managing the distribution of sections within a memory heap forefficient sweeps of larger objects in accordance with the method,system, and program of the present invention

DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT

Referring now to the drawings and in particular to FIG. 1, there isdepicted one embodiment of the hardware and software implemented in acomputer system through which the present method, system, and programmay be implemented. The present invention may be executed in a varietyof systems, including a variety of computing systems and electronicdevices.

Computer system 100 generally includes a bus 122 or other communicationdevice for communicating information within computer system 100, and atleast one processing device, such as processor 112 a, coupled to bus 122for processing information. Bus 122 preferably includes low-latency andhigher latency paths that are connected by bridges and adapters andcontrolled within computer system 100 by multiple bus controllers. Whenimplemented as a server system, computer system 100 typically includesmultiple processors, such as processors 112 a-112 n that operate inparallel to improve network servicing power.

Processors 112 a-112 n may be general-purpose or specified purposeprocessors that, during normal operation, operate under the control ofone or more of a number of different operating systems, such asoperating system 142, and execute various computer softwareapplications, programs, objects, modules and other processes from amemory 114. Although not depicted, memory 114 may include dynamicstorage such as random access memory (RAM) and static storage such asRead Only Memory (ROM). In addition, although not depicted, each ofprocessors 112 a-112 n may include levels of cache and registers localto a central processing unit.

In one embodiment, a Java Virtual Machine (JVM) 140 is loaded in memoryon top of operating system 132. JVM 140 appears as an application to(native) operating system 142, but in fact functions as a virtualoperating system, supporting Java applications. In particular, Javaapplications are preferably portable applications that when run by JVM140, can run on any platform, regardless of operating system or hardwarespecifications. Although not depicted, JVM 140 compiles byte code fromJava applications and a Java interpreter converts the byte code intoinstructions understandable by operating system 142. The components ofJVM 140 may be incorporated into a standalone application, a part of anoperating system, or a part of a larger application, such as a browserapplication or middleware. In an alternate embodiment, JVM 140 and anyof the components of JVM 140 may, at different times, be resident inwhole or in part in any of memory 114, mass storage device 118, network102, or with in registers or cache of processors 112 a-112 n or otherprocessor registers and cache.

In one embodiment, operating system software or JVM 140 contains machineexecutable instructions that when executed on processor 112 carry outthe operations depicted in the flowchart of FIGS. 4, 5, and 6, and otheroperations described herein. Alternatively, the steps of the presentinvention might be performed by specific hardware components thatcontain hardwired logic for performing the steps, or by any combinationof programmed computer components and custom hardware components.

The present invention may be provided as a computer program product,included on a machine-readable medium having stored thereon the machineexecutable instructions used to program computer system 100 to perform aprocess according to the present invention. The term “machine-readablemedium” as used herein includes any medium that participates inproviding instructions to processors 112 a-112 n or other components ofcomputer system 100 for execution. Such a medium may take many formsincluding, but not limited to, non-volatile media, volatile media, andtransmission media. Common forms of non-volatile media include, forexample, a floppy disk, a flexible disk, a hard disk, magnetic tape orany other magnetic medium, a compact disc ROM (CD-ROM) or any otheroptical medium, punch cards or any other physical medium with patternsof holes, a programmable ROM (PROM), an erasable PROM (EPROM),electrically EPROM (EEPROM), a flash memory, any other memory chip orcartridge, or any other medium from which computer system 100 can readand which is suitable for storing instructions. In the presentembodiment, an example of a non-volatile medium is mass storage device118 which as depicted is an internal component of computer system 100,but will be understood to also be provided by an external device.Volatile media include dynamic memory such as RAM. Transmission mediainclude coaxial cables, copper wire or fiber optics, including the wiresthat comprise bus 122. Transmission media can also take the form ofacoustic or light waves, such as those generated during radio frequencyor infrared data communications.

Moreover, the present invention may be downloaded as a computer programproduct, wherein the program instructions may be transferred from aremote system, such as a server 136, to requesting computer system 100by way of data signals embodied in a carrier wave or other propagationmedium via a network link 134 (e.g. a modem or network connection) to acommunications interface 132 coupled to bus 122. Communicationsinterface 132 provides a data communications coupling to network link134 that may be connected, for example, to a local area network (LAN),wide area network (WAN), or directly to an Internet Service Provider(ISP). In particular, network link 134 may provide wired and/or wirelessnetwork communications to one or more networks.

Network link 134 in turn provides data communication services throughnetwork 102. Network 102 may refer to the worldwide collection ofnetworks and gateways that use a particular protocol, such asTransmission Control Protocol (TCP) and Internet Protocol (IP), tocommunicate with one another. Network link 134 and network 102 both useelectrical, electromagnetic, or optical signals that carry digital datastreams. The signals through the various networks and the signals onnetwork link 134 and through communication interface 132, which carrythe digital data to and from computer system 100, are exemplary forms ofcarrier waves transporting the information.

In addition to server 136, any number of computers and other devices maybe networked through network 102. Further, operating system 142, JVM140, and various applications, programs, objects, modules and otherprocesses may execute on one or more processors in server 136 and othercomputer systems accessible via network 102 in a distributedenvironment. In particular, when implemented as a server system,computer system 100 typically includes multiple communication interfacesaccessible via multiple peripheral component interconnect (PCI) busbridges connected to an input/output controller. In this manner,computer system 100 allows connections to multiple networked accessiblecomputers.

In addition, computer system 100 typically includes multiple peripheralcomponents that facilitate communication. These peripheral componentsare connected to multiple controllers, adapters, and expansion slotscoupled to one of the multiple levels of bus 122 and herein referred toby I/O interface 130.

Those of ordinary skill in the art will appreciate that the hardwaredepicted in FIG. 1 may vary and can be implemented within multiple typesof systems. For example, computer 100 can be a standard computer orserver, but can also be an embedded system, such as a set top box,handheld device, or any other hardware device including a processor andJVM 140. Furthermore, those of ordinary skill in the art will appreciatethat the depicted example is not meant to imply architecturallimitations with respect to the present invention.

With reference now to FIG. 2, a block diagram depicts a block diagram ofthe memory management and allocation within a JVM in accordance with themethod, system, and program of the present invention. As depicted, JVM140 includes a memory management controller 202, in addition tointerpreters, controllers, and other components not depicted, buttypically implemented within a JVM.

Initially, memory management controller 202 requests memory space 210from the operating system for storing objects and data for a Javaapplication. In the embodiment depicted, memory management controller202 is a component of JVM 140, however it will be understood that memorymanagement controller 202 may be located within other software systems.

In one embodiment, memory space 210 includes is a contiguous block ofmemory, called the heap. Same sized blocks of heap 220 are representedby bits in an independent bit vector 224. For example, 8-byte blocks ofheap 220 may each be represented by a bit in independent bit vector 224.

In this example of a multiprocessor system, portions of heap 220 areassigned among multiple sections 212 a-212 n. In particular, each ofsections 212 a-212 n is represented by a data structure that includingsection identifiers 218 a-218 n that identify the portions of heap 220and bit vector 224 assigned to each section. In addition, the datastructures representing each of sections 212 a-212 n include local freelists 214 a-214 n and prefix and suffix fields 216 a-216 n.

Memory management controller 202 includes an object allocator 204 and agarbage collector 206. Object allocator 204 controls the allocation ofheap space to objects needed for execution of a Java application.Garbage collector 206 controls the deletion of objects from memory space210 when those objects are no longer required. In particular, anadvantage of the Java programming language is that Java applications donot need to specifically control the allocation or deallocation ofmemory, rather the allocation and deallocation of memory is controlledby JVM 200.

When a request for object allocation is received by JVM 200, objectallocator 204 searches a global free list 222 for a free item providingsufficient allocation space for the new object. Global free list 222 andlocal free lists 214 a-214 n may include, for example, a linked list offree items within heap 220.

When global free list 222 is searched, if a free item providingsufficient allocation space is located, in one example, the free item ispopped from global free list 222 and the new object is allocated withinthe space previously occupied by the free item. If a free item providingsufficient allocation space is not available, in one example, garbagecollection is initiated to free up additional heap space.

Garbage collector 206 may perform garbage collection using mark andsweep phases, for example. During a mark phase, objects that are stillactively referenced in heap 220 are identified and the bit in a bitvector 224 that corresponds to the first byte of each referenced objectis marked.

Next, during garbage collection, in a phase commonly referred to as the“sweep phase”, sufficient helper threads are initiated to use all of theavailable processors. Each of the helper threads may perform an atomicoperation to acquire the next unprocessed section from among sections212 a-212 n and efficiently identify free space. In particular, as willbe described in detail with reference to FIG. 3, each helper threadscans the portion of the bit array assigned to an acquired section tolocate the first marked bit. If no marked bit is found, then the prefixvalue is set to the number of bits in the portion of the bit array andthe next section, if any, is acquired. If a marked bit is found, thenumber of preceding zero bits are stored in the prefix field of thesection data structure. Next, the helper thread counter is reset andthen incremented for each zero in a consecutive sequence following themarked bit. If the counter value exceeds an object fetch threshold, thenthe size of the marked object is fetched and the size indicated by thecounter bits is subtracted from the size of the marked object. If themarked object size exceeds the size indicated by the counter bits, thenthe remainder of the bits representing the marked object are skipped andany consecutive sequence of zero bits following the marked object bitsare counted, indicating potentially free space. Advantageously, byfetching the size of a marked object once the marked object represents apotentially larger marked object, not all the bits of a larger markedobject need be scanned.

Once the end of the section or a marked bit is detected, if aconsecutive sequence of zero bits exceeds a free list size threshold,then the sequence of zero bits is considered a free item and added tothe local free item list. Further, in particular, when the end of thesection is reached, the size indicated by the current counter issubtracted from last marked object size and the value is stored in thesuffix field of the section's data structure. In one example, the suffixvalue will be a zero if the object ends at the boundary, negative if theobject extends beyond the boundary, or positive if there is free storageat the end of the section.

Once all the helper threads complete the sweep of local heaps 218 a-218n, garbage collector 206 acquires a lock on execution by any other Javaprocesses and executes a single thread. The single thread collects allthe free items stored in local free lists 214 a-214 n and combines localfree lists 214 a-214 n into a single global free list 222. In addition,the single thread collects all the prefix/suffix values 216 a-216 n andidentifies free items of sufficient size for the free list that overlapsections.

As will be further described with reference to FIG. 3, when heap 220 isinitially defined, the number of sections and the size of the heaprepresented in each section may be defined to make allocation anddeallocation of large objects more efficient. In particular, in oneexample, the first portion of the heap may be assigned among “n” largersections, where “n” represents the number of helper threads. Inparticular, the size of each portion of the heap assigned among the “n”larger sections may be set such that when a bitwise scan for consecutivesequences of zeroes of a length indicating a potentially free item isperformed during the sweep phase, large marked objects are quicklyidentified and skipped to decrease the performance time for each helperthread in identifying free items. A second portion of the heap assignedamong sections is divided into multiple sections that progressivelydecrease in size. In particular, the number of progressively decreasingsmaller sections may be allocated such that there is a sufficient poolof small sections assigned to the end of the heap to ensure properthread load balancing, but minimize the overall number of sectionsrequired. Overall, by assigning “n” large sections from among oneportion of the heap and then assigning multiple progressively smallersections from among a second portion of the heap, the overall number ofrequired sections is reduced, but efficient handling of large objects ispromoted. In particular, when the number of sections is reduced, theamount of time utilized by the single mode thread is reduced whichincreases the efficiency of garbage collector 206.

Referring now to FIG. 3, an illustrative example depicts an efficientparallel bitwise sweep in accordance with the method, system, andprogram of the present invention. As depicted in the example, portionsof heap 220 are divided among multiple sections.

In particular, in the example, heap 220 is logically divided intomultiple sections delineated as sections A1 and A2 and sections B1-B4.The first portion of heap 220 is distributed among sections A1 and A2,where there are two helper threads available and thus two sectionsdesignated for a first portion of heap 220. The second portion of heap220 is distributed among the data structures for sections B1-B4, wherethe portion of the heap allocated among each of these sectionsprogressively decreases in size. In the example, the first portion ofheap 220 is a little over half of heap 220, however, the size of thefirst portion of heap 220 may be adjusted responsive to recent disparityin the completion times of helper threads.

For purposes of example, heap 220 includes multiple marked objects 302,304, 306, 308, 310 and 312. In the figure, the bottom of memory heap 220represents the address at the start of the heap and the top of the heaprepresents the end of the heap. In addition, as depicted in the figure,objects allocated within heap 220 may vary in size, however, all objectsallocated within heap 220 start on an 8-byte boundary. It will beunderstood that other sizes of byte boundaries may also be implemented.

In one embodiment, the location of the first byte of each markedobjected within heap 220 is depicted by a corresponding bit set in markvector 320. In particular, mark vector 320 is a bit vector with one bitto represent each 8-byte section of heap 220. During the mark phase,bits are set corresponding to the 8-byte section at the start of eachobject that is live. In one example, a live object is one that is stillreferenced by other objects, however other rules may be set for markinglive objects. For purposes of example, only marked objects are depictedwithin heap 220; however heap 220 may also include unmarked objects, aswell previously discarded free items.

After the mark phase, a sweep phase identifies and places free spacethat is larger than a free list size threshold on a free item list orsome other structure to facilitate subsequent object allocation. To findfree spaces larger than a free list size threshold, the garbagecollector performs a bitwise sweep of mark vector 320. In general,during the bitwise sweep, mark vector 320 is scanned for a marked bitfollowed by a run of zeroes that exceed an object fetch threshold. Oncea marked bit followed by a run of zeroes that exceed an object fetchthreshold is identified, the size of the marked object is fetched. Ifthe fetched object size is greater than the size indicated by the run ofzeroes, then the remaining bits corresponding to the object are skippedand the scanning resumes with the bit following the marked object orterminates if the object extends beyond the end of a current section. Ifthe scanning resumes, then the zeroes following the marked object bitsare counted and identified and placed on the free item list if the freeitem represented by the counted zeroes is greater than the free listsize threshold.

It is important to note that the object fetch threshold may be adjustedto optimize skipping over portions of large marked objects. In oneexample, object fetch threshold may be set to a value calculated byadding the smallest possible object sized to the free list sizethreshold, where free items greater than the free list size thresholdare placed on the free list. For purposes of the example only,represented in terms of bit vector sized bits, the object fetchthreshold is set to 4 bits, where the free list size threshold is 3 bitsand the smallest possible object size is 1 bit.

In particular, since heap 300 is logically allocated into sections, oneof multiple helper threads performs the bitwise sweep within eachsection. In particular, in the example, during a bitwise sweep, helperthreads, identified as helper threads 1 and 2, initially acquiresections A1 and A2 and begin sweeping portions of mark vector 320 asillustrated at reference numerals 324 and 326.

When a helper threads begins scanning a section, the helper threadbegins counting the initial number of zeroes in a consecutive sequence.A counter implemented by each helper thread is incremented for eachconsecutive zero scanned. When a marked bit or the end of the section isreached, then a prefix for the section is set to the counter value. Inaddition, if the end of the section is reached, then the helper threadterminates and acquires the next section data structure. In the example,the prefix for section A1 is set to 2 and the prefix for section A2 isset to 0 to represent the number of consecutive zero bits counted beforereaching the first marked bit in each section. In addition, in theexample, the prefixes for section B3 and B4 are set to 4 and 3,respectively, indicating empty sections because the prefix value equalsthe number of bits for the section. By setting the prefix for eachsection, when the results of each helper thread sweep are combined fromthe section data structures, the main thread can easily combine freespace that extends across sections to determine if the free space issufficient in size to be a free item on the global free list.

If a marked bit is reached while scanning an initial sequence of zerobits, then the counter is reset to “1” and the helper thread continuesto increment the counter for each consecutive zero bit scanned. If thecounter exceeds an object fetch threshold, then the size of theinitially marked object is fetched. If the size of the initially markedobject is greater than the size indicated by the counter bits, then theremaining bits identifying the marked object are skipped and the counteris incremented by the number of skipped bits. When the end of thesection or another marked bit are reached, then the size of a free itemis determined by subtracting the last marked object size from the sizeindicated by the counter.

In the example of the scan of section A1, helper thread 1 resets thecounter to “1” when the first marked bit is reached and increments thecounter for each consecutive zero scanned until the counter reaches “5”,which exceeds the object fetch threshold. The size of marked object 302is fetched; the size of marked object is represented by 11 bits. Sincethe size of the marked object exceeds the counter indicated size, theremaining six bits of marked object 302 are skipped and the counter isautomatically incremented by the number of remaining bits. The jump inbit position is illustrated by the helper thread scan discontinuing forthe skipped bits. Next, the helper thread continues to scan the bits andincrement the counter for zero bits. When the end of section A1 isdetected, the suffix for section A1 is set to the size of marked object302 subtracted from the counter indicated size. It is important to notethat by skipping bits of marked object 302, the helper thread moreefficiently scanned section A1 than if each bit of marked object 302 hadbeen scanned.

Once helper thread 1 completes the sweep of section A1, helper thread 1then acquires a next section, which in the example is section B1, andstarts scanning portion of the bit vector assigned to section B1 at thebit indicated at reference numeral 328. The prefix for section B1 is setto indicate the number of zero bits scanned before a marked bit isreached and the counter is reset to “1”. When the end of section B1 isdetected, since the counter has not yet exceeded the object fetchthreshold, the size of marked object 308 is fetched and subtracted fromthe counter indicated size to determine the suffix value for section B1of “1”.

Next, helper thread acquires section B2 and begins scanning the portionof the bit vector assigned to section B2 at the bit indicated atreference numeral 330. There are no zero bits before first marked bitreached in section B2, so the prefix for B2 is set to “0” and thecounter is set to “1”. The counter is reset to “1” when the next markedbit is reached. Advantageously, the size of marked object 310 need notbe fetched because the object fetch threshold was not exceeded, and thusit is not possible for a marked object and free item of sufficient sizeto be represented by the consecutive sequence of zeroes. At the end ofthe section, the counter is set to “3”, the size of marked object 312 isfetched, which is represented by 3 bits and so the suffix for section B2is set to “0”.

Helper thread 2 may begin execution concurrently with helper thread 1,and acquire section A2. In the scan of the portion of the bit vectorassigned to section A2, as depicted starting at reference numeral 326,the initial bit is a “1”, so the prefix for section A2 is set to “0”.The counter is set to “1” and is incremented for each consecutive zero.In this example, the counter exceeds the object fetch threshold and thesize of marked object 304 is fetched; the size for marked object 304 isrepresented by 4 bits. The size of the marked object does not exceed thecounter indicated size, so the thread continues to increment the counterfor each consecutive zero bit. When a marked bit is reached, the size ofa free item is determined. In particular, when the second marked bit isreached in the scan of section A2, the counter has reached “8” and thesize of the previous marked object has already been fetched, so a 4 bitfree item is identified and because the free item exceeds to the 3 bitfree list size threshold the free item is added to section A2's localfree list. The counter is then reset to “1” and the counter isincremented for each consecutive zero bit detected until the counterreaches the object fetch threshold again. This time, the size of markedobject 306 is fetched and the helper thread determines that since themarked object size exceeds the counter indicated size by 2 bits, thelast 2 bits representing marked object 306 can be skipped. In addition,since marked object 306 crosses into section B1, the suffix for A2 isset to indicate the additional size of marked object 306 outside sectionA2.

Helper threads 1 and 2 end by scanning sections B4 and B3, respectively.It will be understood that additional smaller sections may be addedwithin the section portion of the heap. In particular, if the disparitybetween the completion times of the helper threads exceeds an acceptabledisparity range, then the second portion of the heap may be increased insize and additional smaller sections added.

It is important to note that while the present invention has beendescribed with reference to a helper thread that scans each bit, helperthreads may alternatively grab a series of bits and quickly determine ifall the bits in the series are zero bits. In addition, other code leveltechniques may be used that increase the efficiency of scanningconsecutive sequence of zero bits.

As depicted, to improve the efficiency of sweeps of large objects, it isimportant to fetch the size of potentially large marked objects, so thatif the marked object exceeds the object fetch threshold, the remainderof the bits representing the marked object in the bit vector can beskipped. In addition, however, it is important to provide sections largeenough to hold objects larger than the object fetch threshold, such thatthe time savings of prematurely fetching the size of a marked object andskipping remaining bits can be used.

While, the present embodiment illustrates a bitwise sweep method andmemory allocation for improved garbage collection efficiency when theheap includes larger objects, smaller objects are also efficiently addedto a free list or discarded to improve the overall efficiency. Inparticular, the size assignments of sections B1-B4 illustrate theadvantage of having multiple smaller sections following the largersections to reduce the disparity of time between each of the helperthreads completing the sweep of a selection of the sections and toquickly sweep sections. As depicted, as the sizes of the portion of theheap assigned to each of sections B1-B4 decreases, the number of bitsthat can potentially be scanned in each section is reduced. Inparticular, advantageously, if the disparity between completion times ofhelper threads scanning the first portion of sections is large, thedisparity may narrow as the sweep times decrease in sections B1-B5.

With reference now to FIG. 4, there is depicted a high level logicflowchart of a process and program for performing a parallel bitwisesweep in accordance with the method, system, and program of the presentinvention. As depicted, the process starts at block 400 and thereafterproceeds to block 402. Block 402 depicts automatically incrementing theindex into the section numbers. Next, block 404 depicts a determinationwhether the index number is greater than the last index numberindicating the end of the section. If the index number is greater thanthe last index number indicating the end of the sections, then theprocess ends. If the index number is not greater than the last indexnumber indicating the end of the sections, then the process passes toblock 406.

Block 406 depicts initializing the fields for the currently indexedsection. Next, block 408 depicts setting a thread counter to “0”.Thereafter, block 410 depicts incrementing the counter for each zero bitin an initial run of zero bits. Next, block 412 depicts a determinationwhether a marked bit or end of section bit is reached. If a marked bitor end of section is not yet reached, then the process returns to block410. If a marked bit or end of section is reached, then the processpasses to block 414. Block 414 depicts setting the indexed sectionprefix to the counter value, and the process passes to block 416.

Block 416 depicts a determination whether the end of the section isreached. If the end of the section is reached, then the process returnsto block 402. If the end of the section is not reached, then the processpasses to block 418.

Block 418 depicts resetting the counter to “1”. Next, block 420 depictsincrementing the counter if the next bit detected in the mark array is azero bit. Thereafter, block 422 depicts a determination whether the endof a section is reached. If the end of the section is reached, then theprocess passes to block 424. Block 424 depicts fetching the size of thelast marked object. Next, block 426 depicts setting the suffix to thecounter indicated size less the size of the last marked object, and theprocess returns to block 402. In one example, the counter indicated sizemay be calculated by multiplying the counter value times the grain size,such as 8 bytes. Alternatively, the size of the marked object may berepresented in terms of bits.

Returning to block 422, if the end of the section is not reached, thenthe process passes to block 428. Block 428 depicts a determinationwhether the counter is greater than an object fetch threshold. If thecounter is not greater than an object fetch threshold, then the processpasses to block 430. Block 430 depicts a determination whether a markedbit is reached. If a marked bit is not reached, then the process returnsto block 420. If a marked bit is reached, then the process returns toblock 418.

Returning to block 428, if the counter is greater than an object fetchthreshold, then the process passes to block 432. Block 432 depictsfetching the size of the last marked object. Next, block 434 depicts adetermination whether the marked object size is greater than the counterindicated size. If the marked object size is greater than the counterindicated size, then the process passes to block 436. Block 436 depictssetting the bit position to the end of the marked object. Next, block437 depicts incrementing the counter for the number of bits skipped, andthe process passes to block 440. Otherwise, at block 438, if the markedobject size is not greater than the counter indicated size, then theprocess passes to block 440.

Block 440 depicts increment the counter if the next bit is a zero bit.Next, block 442 depicts a determination whether the end of the sectionis reached. If the end of the section is reached, then the processpasses to block 426. Otherwise, at block 442, if the end of the sectionis not reached, then the process passes to block 444. Block 444 depictsa determination whether a marked bit is reached. If a marked bit is notreached, then the process returns to block 440. If a marked bit isreached, then the process passes to block 446.

Block 446 depicts setting the size of the free item to the counterindicated size less the size of the last marked object. Next, block 448depicts a determination whether the size of the free item is greaterthan a free list size threshold. If the size of the free item is notgreater than the free list size threshold, then the process returns toblock 418. Otherwise, at block 448, if the size of the free item isgreater than the free list size threshold, then the process passes toblock 450. Block 450 depicts putting the free item on the free list, andthe process returns to block 418.

Referring now to FIG. 5, there is depicted a high level logic flowchartof a process and program for initially distributing sections within amemory heap for efficient sweeps of larger objects in accordance withthe method, system, and program of the present invention. As depicted,the process starts at block 500 and thereafter proceeds to block 502.Block 502 depicts distributing a first portion of the heap to a numberof sections equal to the number of allocable helper threads for garbagecollection. Next, block 504 depicts distributing a second portion of theheap over a number a sections that progressively decrease in size, andthe process ends. It is important to note that in distributing portionsof the heap to sections, a data structure is created for each sectionthat indicates the portion of the heap assigned to the section and theportion of the bit arrays assigned to each section. In addition, it isimportant to note that in distributing portions of the heap to sections,the size of the portion of the heap assigned to each of the sections inthe first portion may reflect the object fetch threshold required forearly fetching of a size of a marked object.

With reference now to FIG. 6, there is depicted a high level logicflowchart of a process and program for managing the distribution ofsections within a memory heap for efficient sweeps of larger objects inaccordance with the method, system, and program of the presentinvention. As depicted, the process starts at block 600 and thereafterproceeds to block 602. Block 602 depicts monitoring the disparity inhelper thread completion times. Next, block 606 depicts a determinationwhether the time disparity is within a threshold range. If the timedisparity is within a threshold range, then the process ends. If thetime disparity is not within a threshold range, then the process passesto block 608. Block 608 depicts a determination whether the timedisparity is less than a threshold range. If the time disparity is lessthan a threshold range, then the process passes to block 612. Block 612depicts increasing the size of the first portion of the heap, and theprocess returns to block 500. Otherwise, at block 608, if the timedisparity is not less than a threshold range, then the process passes toblock 610. Block 610 depicts decreasing the size of the first portion ofthe heap, and the process returns to block 500.

While the invention has been particularly shown and described withreference to a preferred embodiment, it will be understood by thoseskilled in the art that various changes in form and detail may be madetherein without departing from the spirit and scope of the invention.

1. A system for an efficient sweep of a memory heap, comprising: meansfor distributing a bit vector comprising a plurality of bits of saidmemory heap among a plurality of sections; means for scanning eachseparate section of said plurality of sections of said bit vector inparallel with one from among a plurality of helper threads furthercomprising: means for incrementing a separate counter to indicate anumber of unmarked bits in an initial consecutive sequence of unmarkedbits within said separate section until an end of said separate sectionis reached or a marked bit is detected; means for setting a separateprefix value equal to said separate counter, wherein said separateprefix value indicates a number of potentially free bits at thebeginning of said separate section; means, responsive to detecting amarked bit, for scanning said separate section of said bit vector tocount a consecutive sequence of unmarked bits reaching a sufficientlength following said marked bit; means, responsive to detecting saidcount of said consecutive sequence of unmarked bits reaching saidsufficient length, for stopping said count of said consecutive sequenceof unmarked bits and for fetching a size of a marked object starting atsaid marked bit; means, responsive to said size of said marked objectexceeding a size represented by said consecutive sequence of unmarkedbits, for skipping a remainder of bits representing said marked objectand counting a next consecutive sequence of unmarked bits indicatingfree space until an end of said separate section is reached or a nextmarked bit is detected, wherein once a marked object is identified aspotentially exceeding a threshold size said scan efficiently skips saidremainder of bits and continues scanning to count consecutive unmarkedbits indicating free space; means, responsive to reaching an end of saidseparate section, for setting a suffix value to a difference between thecurrent number of unmarked bits following a last marked bit within saidseparate section and a size of an object associated with said lastmarked bit; and means, responsive to said plurality of helper threadscompleting scanning of said plurality of sections, for collecting eachseparate prefix value, each separate count indicating free space, andeach separate suffix value for each of said plurality of sections into aglobal list identifying free space for said memory heap which specifiesfree space that spans across a selection of said plurality of sectionsfrom each said separate prefix value and each said separate suffixvalue.
 2. The system according to claim 1 for an efficient sweep of amemory heap further comprising: means for counting a second consecutivesequence of unmarked bits following said remainder of bits, wherein saidsecond consecutive sequence of unmarked bits represents a free item of asize that exceeds a free list size threshold; and means for placing saidfree item on a free item list for said separate section.
 3. The systemaccording to claim 1 for an efficient sweep of a memory heap, furthercomprising: means for scanning each of said plurality of sections ofsaid bit vector in parallel with one from among a plurality of helperthreads, wherein each of said plurality of helper threads is enabled toacquire a next available section from among said plurality of sectionsduring a sweep mode, wherein each of said plurality of helper threads isenabled to count any consecutive sequences of unmarked bits representinga free item into a separate local free list associated with eachseparate section from among said plurality of sections; and means forcollecting each free item from each separate local free list and eachsaid prefix value and each said suffix value for each separate sectionwith a single thread from among said plurality of helper threads intosaid global free list.
 4. The system according to claim 1 for anefficient sweep of a memory heap, further comprising: means fordistributing a first portion of said bit vector and said heap among afirst plurality of sections equal to a number of said plurality ofhelper threads; and means for distributing a second portion of said bitvector and said heap among a second plurality of sections, wherein asize of said bit vector and said heap distributed among each of saidsecond plurality of section progressively decreases among said secondplurality of sections.
 5. The system according to claim 1, wherein saidmeans, responsive to reaching an end of said separate section, forsetting a suffix value to a difference between the current number ofunmarked bits following a last marked bit within said separate sectionand a size of an object associated with said last marked bit, furthercomprises: means for setting a suffix value to a negative value whensaid current number of unmarked bits following a last marked bit is lessthan said size of said object associated with said last marked bit.
 6. Acomputer program product, residing on a volatile or non-volatilemachine-readable medium, for an efficient sweep of a memory heap,comprising: means for distributing a bit vector comprising a pluralityof bits of said memory heap among a plurality of sections; means forscanning each separate section of said plurality of sections of said bitvector in parallel with one from among a plurality of helper threadsfurther comprising: means for incrementing a separate counter toindicate a number of unmarked bits in an initial consecutive sequence ofunmarked bits within said separate section until an end of said separatesection is reached or a marked bit is detected; means for setting aseparate prefix value equal to said separate counter, wherein saidseparate prefix value indicates a number of potentially free bits at thebeginning of said separate section; means, responsive to detecting amarked bit, for scanning said separate section of said bit vector tocount a consecutive sequence of unmarked bits reaching a sufficientlength following said marked bit; means, responsive to detecting saidcount of said consecutive sequence of unmarked bits reaching saidsufficient length, for stopping said count of said consecutive sequenceof unmarked bits and for fetching a size of a marked object starting atsaid marked bit; means, responsive to said size of said marked objectexceeding a size represented by said consecutive sequence of unmarkedbits, for skipping a remainder of bits representing said marked objectand counting a next consecutive sequence of unmarked bits indicatingfree space until an end of said separate section is reached or a nextmarked bit is detected, wherein once a marked object is identified aspotentially exceeding a threshold size said scan efficiently skips saidremainder of bits and continues scanning to count consecutive unmarkedbits indicating free space; means, responsive to reaching an end of saidseparate section, for setting a suffix value to a difference between thecurrent number of unmarked bits following a last marked bit within saidseparate section and a size of an object associated with said lastmarked bit; and means, responsive to said plurality of helper threadscompleting scanning of said plurality of sections, for collecting eachseparate prefix value, each separate count indicating free space, andeach separate suffix value for each of said plurality of sections into aglobal list identifying free space for said memory heap which specifiesfree space that spans across a selection of said plurality of sectionsfrom each said separate prefix value and each said separate suffixvalue.
 7. The computer program product according to claim 6 for anefficient sweep of a memory heap further comprising: means for countinga second consecutive sequence of unmarked bits following said remainderof bits, wherein said second consecutive sequence of unmarked bitsrepresents a free item of a size that exceeds a free list sizethreshold; and means for placing said free item on a free item list forsaid separate section.
 8. The computer program product according toclaim 6 for an efficient sweep of a memory heap, further comprising:means for scanning each of said plurality of sections of said bit vectorin parallel with one from among a plurality of helper threads, whereineach of said plurality of helper threads is enabled to acquire a nextavailable section from among said plurality of sections during a sweepmode, wherein each of said plurality of helper threads is enabled tocount any consecutive sequences of unmarked bits representing a freeitem into a separate local free list associated with each separatesection from among said plurality of sections; and means for collectingeach free item from each separate local free list and each said prefixvalue and each said suffix value for each separate section with a singlethread from among said plurality of helper threads into said global freelist.
 9. The computer program product according to claim 6 for anefficient sweep of a memory heap, further comprising: means fordistributing a first portion of said bit vector and said heap among afirst plurality of sections equal to a number of said plurality ofhelper threads; and means for distributing a second portion of said bitvector and said heap among a second plurality of sections, wherein asize of said bit vector and said heap distributed among each of saidsecond plurality of section progressively decreases among said secondplurality of sections.
 10. The computer program product according toclaim 6, wherein said means, responsive to reaching an end of saidseparate section, for setting a suffix value to a difference between thecurrent number of unmarked bits following a last marked bit within saidseparate section and a size of an object associated with said lastmarked bit, further comprises: means for setting a suffix value to anegative value when said current number of unmarked bits following alast marked bit is less than said size of said object associated withsaid last marked bit.